package org.xteam.camllight;

public class CodeStream {

	private byte[] code;
	private int pc;

	public CodeStream(byte[] code) {
		this.code = code;
		this.pc = 0;
	}

	public int getUI8() {
		return code[pc++] & 0xff;
	}

	public int getSI16() {
		int b = getUI16();
		if ((b & 0x8000) != 0) {
			return b - 0x10000;
		}
		return b;
	}
	
	public int getUI16() {
		int b = getUI8();
		return b | (getUI8()<<8);
	}
	
	public int getUI32() {
		int b = getUI16();
		return b | (getUI16()<<16);
	}

	public int pc() {
		return pc;
	}

	public void goTo(int newPc) {
		pc = newPc;
	}

	public void setPc(int pc) {
		this.pc = pc;
	}

}
